package Java攻略._3_流式操作._7_获取元素数量;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class _41_对根据长度划分的字符串计数 {

    public static void main(String[] args) {

        List<String> strings = new ArrayList<>();
        strings.add("1");
        strings.add("12");
        strings.add("123");
        strings.add("1234");

        Map<Boolean, Long> numberLengthMap = strings.stream()
                .collect(Collectors.partitioningBy(
                        s -> s.length() % 2 == 0,
                        Collectors.counting()
                ));

        numberLengthMap.forEach(
                (k,v) -> System.out.printf("%5s : %d%n",k,v)
        );
    }
}
